<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.name"
        placeholder="项目名称"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.name"
        placeholder="项目编号"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-date-picker
        v-model="listQuery.publish_date"
        type="datetime"
        class="filter-item"
        placeholder="选择日期时间"
        style="width: 150px"
      />
      <el-date-picker
        v-model="listQuery.publish_date"
        type="datetime"
        class="filter-item"
        placeholder="报名截止时间"
        style="width: 150px"
      />
      <el-date-picker
        v-model="listQuery.publish_date"
        type="datetime"
        class="filter-item"
        placeholder="评标时间"
        style="width: 150px"
      />

      <el-date-picker
        v-model="listQuery.publish_date"
        type="datetime"
        class="filter-item"
        placeholder="投标截止时间"
        style="width: 150px"
      />
      <el-select
        v-model="listQuery.contract"
        class="filter-item"
        placeholder="联系人"
        style="width: 100px"
      >
        <el-option
          v-for="option in options"
          :label="option.label"
          :value="option.value"
          :key="option.value"
        ></el-option>
      </el-select>

      <el-button class="filter-item" type="primary" icon="el-icon-search">
        查询
      </el-button>
      <el-button class="filter-item" type="primary" icon="el-icon-refresh">
        重置
      </el-button>
      <el-button
        v-permission="['purchaser']"
        icon="el-icon-plus"
        type="success"
        class="filter-item"
        @click="dialogVisibleCreate = true"
        >新建招标项目
      </el-button>
    </div>
    <el-tabs
      v-model="activeName"
      type="card"
      v-if="checkPermission(['expert'])"
    >
      <el-tab-pane label="全部" name="1"></el-tab-pane>
      <el-tab-pane label="评标中（10）" name="2"></el-tab-pane>
      <el-tab-pane label="已结束（3）" name="3"></el-tab-pane>
    </el-tabs>
    <el-tabs
      v-model="activeName"
      type="card"
      v-if="checkPermission(['purchaser', 'bidder'])"
    >
      <el-tab-pane label="全部" name="1"></el-tab-pane>
      <el-tab-pane label="待提交" name="2"></el-tab-pane>
      <el-tab-pane label="招标中" name="3"></el-tab-pane>
      <el-tab-pane label="投标中" name="4"></el-tab-pane>
      <el-tab-pane label="开标中" name="5"></el-tab-pane>
      <el-tab-pane label="评标中" name="6"></el-tab-pane>
      <el-tab-pane label="定标中" name="7"></el-tab-pane>
      <el-tab-pane label="已完成" name="8"></el-tab-pane>
      <el-tab-pane label="跟标" name="9"></el-tab-pane>
    </el-tabs>
    <el-tabs
      v-model="activeName"
      type="card"
      v-if="checkPermission(['supplier'])"
    >
      <el-tab-pane label="全部" name="1"></el-tab-pane>
      <el-tab-pane label="待审核（3）" name="2"></el-tab-pane>
      <el-tab-pane label="待审通过（13）" name="3"></el-tab-pane>
      <el-tab-pane label="待审不通过（2）" name="4"></el-tab-pane>
    </el-tabs>
    <el-table :data="list" border highlight-current-row>
      <el-table-column
        label="序号"
        type="index"
        width="60"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="name"
        label="项目名称"
        width="260"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="招标方式"
        prop="type"
        width="80"
        align="center"
      ></el-table-column>
      <el-table-column
        label="手机号码"
        prop="mobile"
        width="120"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="date"
        align="center"
        label="报名截止时间"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="date"
        align="center"
        label="投标截止时间"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="date"
        align="center"
        label="评标时间"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="address"
        label="评标地址"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        v-if="checkPermission(['purchaser'])"
        prop="status"
        label="状态"
        width="120"
        align="center"
      ></el-table-column>
      <el-table-column
        label="状态"
        v-if="checkPermission(['supplier'])"
        width="120"
        align="center"
      >
        <template>
          <span>{{ Math.random() > 0.5 ? "审核通过" : "审核不通过" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        v-if="checkPermission(['expert'])"
        width="120"
        align="center"
      >
        <template>
          <span>{{ Math.random() > 0.5 ? "评标中" : "已结束" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <div>
            <el-button type="text" @click="$router.push('/bidding/detail')"
              >查看
            </el-button>

            <el-button
              v-if="checkPermission(['purchaser', 'bidder'])"
              @click="$router.push('/bidding/select')"
              type="text"
              >选择入围
            </el-button>
            <el-button
              v-if="checkPermission(['bidder'])"
              @click="$router.push('/bidding/open')"
              type="text"
              >开标
            </el-button>

            <el-button
              v-if="checkPermission(['expert'])"
              @click="handleExpertOpen"
              type="text"
              >评标
            </el-button>
            <el-button
              v-else
              type="text"
              @click="$router.push('/bidding/evaluation')"
              >评标
            </el-button>
            <el-button
              v-if="checkPermission(['supplier'])"
              @click="$router.push('/bidding/detail?tab=1')"
              type="text"
              >报名
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <el-dialog title="开标解密" :visible.sync="dialogVisible" width="400px">
      <el-form :model="form" label-width="80px">
        <el-form-item label="开标密码" required>
          <el-input v-model="form.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleOpen">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 专家签到 -->
    <el-dialog title="签到确认" :visible.sync="dialogVisibleExpert" width="30%">
      <el-form :model="form1" label-width="120px">
        <el-form-item label="询单名称">招标名称</el-form-item>
        <el-form-item label="询单编号">123456789123456789</el-form-item>
        <el-form-item label="签到会议室">
          <el-select v-model="form1.option">
            <el-option label="第一会议室" value="1"></el-option>
            <el-option label="第二会议室" value="2"></el-option>
            <el-option label="第三会议室" value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleExpert = false">取 消</el-button>
        <el-button type="primary" @click="handleEvaluation">确 定 </el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="选择招标方式"
      :visible.sync="dialogVisibleCreate"
      width="400px"
    >
      <el-row :gutter="24">
        <el-col :md="12">
          <el-card shadow="hover">
            <div class="switch-choice" @click="goCreate">
              <i class="el-icon-s-flag"></i>
              <span>简易综合比价模式</span>
            </div>
          </el-card>
        </el-col>
        <el-col :md="12">
          <el-card shadow="hover">
            <div class="switch-choice" @click="goCreate">
              <i class="el-icon-s-check"></i>
              <span>高级综合比价模式</span>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";

export default {
  name: "PurchaseIndex",
  data() {
    return {
      total: 0,
      list: [
        {
          date: "2016-05-02",
          name: "项目名称1",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1518 弄",
          status: "草稿",
        },
        {
          date: "2016-05-04",
          name: "项目名称2",
          type: "公开",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1517 弄",
          status: "审核中",
        },
        {
          date: "2016-05-01",
          name: "项目名称3",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1519 弄",
          status: "审核不通过",
        },
        {
          date: "2016-03-03",
          name: "项目名称4",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1516 弄",
          status: "发布招标预告",
        },
        {
          date: "2016-05-19",
          name: "项目名称5",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1516 弄",
          status: "发布招标预告",
        },
        {
          date: "2016-05-03",
          name: "项目名称6",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1516 弄",
          status: "发布招标预告",
        },
        {
          date: "2016-05-03",
          name: "项目名称7",
          type: "邀请",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1516 弄",
          status: "发布招标预告",
        },
        {
          date: "2016-05-03",
          name: "项目名称8",
          type: "公开",
          mobile: "18956235465",
          address: "上海市普陀区金沙江路 1516 弄",
          status: "发布招标预告",
        },
      ],
      listQuery: {
        page: 1,
        limit: 20,
        publish_date: undefined,
        name: undefined,
        contract: "",
        status: "1",
      },
      options: [],
      activeName: "1",
      dialogVisible: false,
      form: {
        password: "",
      },
      dialogVisibleExpert: false,
      form1: {
        option: "",
      },
      dialogVisibleCreate: false,
    };
  },
  components: {
    Pagination,
  },
  methods: {
    getList() {},
    handleFilter() {},
    // 创建
    goCreate() {
      this.dialogVisibleCreate = false;
      setTimeout(() => {
        this.$router.push({
          name: "BiddingCreate",
        });
      }, 200);
    },

    // 选择入围供应商
    goSelected() {
      this.$router.push({
        name: "BiddingSelect",
      });
    },
    // 开标
    handleOpen() {
      this.dialogVisible = false;
      setTimeout(() => {
        this.$router.push({
          name: "BiddingOpen",
        });
      }, 300);
    },
    // 评标
    handleEvaluation() {
      this.dialogVisibleExpert = false;
      setTimeout(() => {
        this.$router.push({
          name: "BiddingEvaluation",
        });
      }, 300);
    },
    handleExpertOpen() {
      this.dialogVisibleExpert = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.switch-choice {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  i {
    font-size: 30px;
    margin-bottom: 30px;
  }
}
</style>
